package com.globalwave.eps.service;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.globalwave.base.BaseServiceImpl;
import com.globalwave.common.ArrayOrderList;
import com.globalwave.common.ArrayPageList;
import com.globalwave.eps.entity.ElectricityProjectLine;
import com.globalwave.eps.entity.ElectricityProjectLineCriterion;

@Service("electricityProjectLineService")
@Scope("prototype")
@Transactional
public class ElectricityProjectLineServiceImpl 
       extends BaseServiceImpl 
       implements ElectricityProjectLineService {

    public ElectricityProjectLine create(ElectricityProjectLine electricityProjectLine) throws Exception {
        return (ElectricityProjectLine) jdbcDao.insert(electricityProjectLine);
    }

    public void update(ElectricityProjectLine electricityProjectLine) throws Exception {
        jdbcDao.update(electricityProjectLine) ;
    }

    public void delete(ElectricityProjectLine electricityProjectLine) throws Exception {
        // delete cascade 
        //OrganizationElectricityProjectLine orgElectricityProjectLine = new OrganizationElectricityProjectLine() ;
        //orgElectricityProjectLine.setElectricityProjectLine_id(electricityProjectLine.getElectricityProjectLine_id()) ;
        //jdbcDao.delete(OrganizationElectricityProjectLine.class, orgElectricityProjectLine) ;
        
        jdbcDao.delete(electricityProjectLine) ;
        
    }

    public void deleteAll(Long[] ids) throws Exception {
        ElectricityProjectLineCriterion criterion = new ElectricityProjectLineCriterion() ;
        criterion.setIds(ids) ;
        jdbcDao.delete(ElectricityProjectLine.class, criterion) ;
        
    }

    public ArrayPageList<ElectricityProjectLine> query(
            ElectricityProjectLineCriterion criterion, 
            int pageIndex, 
            int pageSize, 
            ArrayOrderList orderList) throws Exception {
        
        if (orderList == null) {
            orderList = new ArrayOrderList() ;
            //orderList.addAsc("electricityProjectLine_id") ;
        }
        
        return (ArrayPageList<ElectricityProjectLine>)jdbcDao.query(criterion, pageIndex, pageSize, orderList, ElectricityProjectLine.class);
    }


    public List<ElectricityProjectLine> queryByProjectId(Long projectId) throws Exception {
    	
    	ArrayOrderList orderList = new ArrayOrderList() ;
        orderList.addAsc("line_number") ;

        ElectricityProjectLineCriterion criterion = new ElectricityProjectLineCriterion() ;
        criterion.setProject_id(projectId) ;
        
        return (List<ElectricityProjectLine>)jdbcDao.query(criterion, orderList, ElectricityProjectLine.class);
    }
    
}
